#include <iostream>
#include <pthread.h>
#include <string>
#include <unistd.h>

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void* route(void *arg)
{
    std::string str = static_cast<const char*>(arg);
    while(1)
    {
        pthread_mutex_lock(&mutex);
        pthread_cond_wait(&cond, &mutex);
        std::cout << str << "正在执行中。。。" << std::endl;
        pthread_mutex_unlock(&mutex);
    }
    return nullptr;
}

int main()
{
    pthread_t t1, t2;
    pthread_create(&t1, nullptr, route, (void*)"thread-1");
    pthread_create(&t2, nullptr, route, (void*)"thread-2");

    while (1)
    {
        usleep(1000000);
        // pthread_cond_signal(&cond);
        pthread_cond_broadcast(&cond);
    }
    
    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);
    return 0;
}